package com.pirestupppai.ui.activity;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.pirestupppai.R;
import com.pirestupppai.base.BaseActivity;
import com.pirestupppai.network.NetworkRequest;
import com.pirestupppai.network.TupaiSubscriber;
import com.pirestupppai.utils.Utils;

import butterknife.BindView;

/**
 * 反馈
 *
 * @author: xiaoluo
 * @date: 2017-04-27 16:04
 */
public class FeedBackActivity extends BaseActivity {

    @BindView(R.id.feedback_back_btn)
    ImageView backBtn;
    @BindView(R.id.feedback_send_tv)
    TextView sendTv;
    @BindView(R.id.feedback_et)
    EditText editText;

    @Override
    protected Context getActivityContext() {
        return this;
    }

    @Override
    protected int loadParentLayout() {
        return R.layout.activity_feedback;
    }

    @Override
    protected void initViews() {
    }

    @Override
    protected void initListeners() {
        backBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        sendTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (TextUtils.isEmpty(editText.getText().toString().trim())) {
                    Utils.showToast("反馈内容不能为空");
                    return;
                }
                if (editText.getText().toString().trim().length() < 5 || editText.getText().toString().trim().length() > 200) {
                    Utils.showToast("反馈字数5-200");
                    return;
                }
                feedBack();
            }
        });
    }

    private void feedBack() {
        NetworkRequest.getInstance().feedback(editText.getText().toString().trim(), this,
                new TupaiSubscriber(mContext) {
                    @Override
                    protected void requestSuccess(Object o) {
                        Utils.showToast("反馈成功!");
                        finish();
                    }

                    @Override
                    protected void requestError(String error) {

                    }
                });
    }

    @Override
    protected void initLogic() {

    }

    @Override
    public void onClick(View v) {

    }
}
